package cn.edu.zafu.bigdata.lekang.shiyan5;

public class ArithmeticExceptionHandling {

    public static void main(String[] args) {
        // 测试数据
        int numerator = 10;
        int denominator = 0;

        try {
            // 调用 divide 方法
            int result = divide(numerator, denominator);
            System.out.println("结果: " + result);
        } catch (ArithmeticException e) {
            // 捕获并处理 ArithmeticException
            System.out.println("错误: " + e.getMessage());
        }
    }


    public static int divide(int a, int b) throws ArithmeticException {
        if (b == 0) {
            throw new ArithmeticException("分母不能为0");
        }
        return a / b;
    }
}
